/*
 * Copyright 2008 Zoundry LLC, Inc.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 */
package org.zoundry.gaedt.ui.editors.application;

import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.zoundry.gaedt.core.models.application.IZGaeHandlerModel;
import org.zoundry.gaedt.core.models.application.IZGaeHandlerVisitor;
import org.zoundry.gaedt.core.models.application.ZGaeScriptHandlerModel;
import org.zoundry.gaedt.core.models.application.ZGaeStaticDirectoryHandlerModel;
import org.zoundry.gaedt.core.models.application.ZGaeStaticFilePatternHandlerModel;
import org.zoundry.gaedt.ui.ZGaeUIImages;

/**
 * Implements a label provider for handlers in an application.
 */
public class ZGaeHandlerLabelProvider extends LabelProvider implements IZGaeHandlerVisitor
{
    /** The handler icon to use for the current handler request. */
    private Image mHandlerIcon;

    /**
     * C'tor.
     */
    public ZGaeHandlerLabelProvider()
    {
    }

    /**
     * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
     */
    @Override
    public Image getImage(Object aElement)
    {
        IZGaeHandlerModel model = (IZGaeHandlerModel) aElement;
        model.accept(this);
        return mHandlerIcon;
    }

    /**
     * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
     */
    @Override
    public String getText(Object aElement)
    {
        IZGaeHandlerModel model = (IZGaeHandlerModel) aElement;
        return model.getUrl();
    }

    /**
     * @see org.zoundry.gaedt.core.models.application.IZGaeHandlerVisitor#visit(org.zoundry.gaedt.core.models.application.ZGaeScriptHandlerModel)
     */
    public void visit(ZGaeScriptHandlerModel aHandler)
    {
        mHandlerIcon = ZGaeUIImages.getImage("icons/editors/application/script.png");
    }

    /**
     * @see org.zoundry.gaedt.core.models.application.IZGaeHandlerVisitor#visit(org.zoundry.gaedt.core.models.application.ZGaeStaticDirectoryHandlerModel)
     */
    public void visit(ZGaeStaticDirectoryHandlerModel aHandler)
    {
        mHandlerIcon = ZGaeUIImages.getImage("icons/editors/application/staticDir.png");
    }

    /**
     * @see org.zoundry.gaedt.core.models.application.IZGaeHandlerVisitor#visit(org.zoundry.gaedt.core.models.application.ZGaeStaticFilePatternHandlerModel)
     */
    public void visit(ZGaeStaticFilePatternHandlerModel aHandler)
    {
        mHandlerIcon = ZGaeUIImages.getImage("icons/editors/application/staticFiles.png");
    }
}
